namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System.Xml.Serialization;
    using SimpleWebServices;
    using Xunit;

    public sealed class ButtonInputFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<ButtonInput>()
                .DerivesFrom<Input>()
                .IsConcreteClass()
                .IsUnsealed()
                .HasDefaultConstructor()
                .Implements<IXmlSerializable>()
                .XmlRoot("input")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            ButtonInput expected = new ButtonInput(new Name("id"))
            {
                Class = "class",
                Accesskey = 'a',
                AlternativeText = "alternative",
                Disabled = true,
                Language = "fr",
                ReadOnly = true,
                Size = 50,
                TabIndex = 1,
                Value = "value"
            };

            string xml = "<input id='id' class='class' lang='fr' name='id' accesskey='a' alt='alternative' tabindex='1' disabled='disabled' readonly='readonly' size='50' type='button' value='value' />";
            ButtonInput actual = xml.Deserialize<ButtonInput>();

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }

        [Fact]
        public void deserializeEmpty()
        {
            Assert.NotNull("<input type='button' />".Deserialize<ButtonInput>());
        }

        [Fact]
        public void serialize()
        {
            ButtonInput obj = new ButtonInput(new Name("id"))
            {
                Class = "class",
                Accesskey = 'a',
                AlternativeText = "alternative",
                Disabled = true,
                Language = "fr",
                ReadOnly = true,
                Size = 50,
                TabIndex = 1,
                Value = "value"
            };

            string xpath = "1=count(/input[@id='id'][@class='class'][@lang='fr'][@name='id'][@tabindex='1'][@disabled='disabled'][@accesskey='a'][@alt='alternative'][@readonly='readonly'][@size='50'][@type='button'][@value='value'])";

            Assert.True((bool)obj.Serialize().CreateNavigator().Evaluate(xpath));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new ButtonInput());
        }

        [Fact]
        public void ctor_Name()
        {
            Assert.NotNull(new ButtonInput(new Name("id")));
        }

        [Fact]
        public void ctor_NameNull()
        {
            Assert.NotNull(new ButtonInput(null));
        }

        [Fact]
        public void prop_Type()
        {
            Assert.True(new PropertyExpectations(typeof(ButtonInput).GetProperty("Type"))
                .DefaultValueIs("button")
                .Result);
        }

        [Fact]
        public void op_Deserialize_string_string_string()
        {
            ButtonInput expected = new ButtonInput(new Name("id"))
            {
                Class = "class",
                Accesskey = 'a',
                AlternativeText = "alternative",
                Disabled = true,
                Language = "fr",
                ReadOnly = true,
                Size = 50,
                TabIndex = 1,
                Value = "value"
            };

            string xml = "<input id='id' class='class' lang='fr' name='id' accesskey='a' alt='alternative' tabindex='1' disabled='disabled' readonly='readonly' size='50' type='button' value='value' />";
            ButtonInput actual = new ButtonInput().Deserialize("input", "button", xml) as ButtonInput;

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }
    }
}